update dynamic 1

Documentation Version for Comments and Changes

You are invited to make any changes...add any comments.

Changes will `eventually` be merged into the offical documentation.

Leave any commnents here...

...

... back to index page OE documentation



Indirect Routine Calling

Euphoria does not have function pointers. However, it enables you to call any routine, including some internal to the interpreter, in an indirect way, using two different sets of identifiers.

Indirect Calling a Routine Coded in Euphoria

The following applies to any routine coded in Euphoria that your program uses, whether it is defined in the standard library, any third party library or your own code. It does not apply to routines implemented in the backend.

Getting a Routine Identifier

Whenever a routine is in scope, you can supply its name to the builtin routine_id function, which returns a small integer:

include get.e 
constant value_id = routine_id("value") 

Because value is defined as public, that routine is in scope. This ensures the call succeeds. A failed call returns -1, else a small nonnegative integer.

You can then feed this integer to call_func or call_proc as appropriate. It does not matter whether the routine is still in scope at the time you make that call. Once the id is gotten, it's valid.

Calling Euphoria Routines by Id

This is very similar to using c_func or c_proc to interface with external code.

Function Calling

This is done as follows:

result = call_func(id_of_the_routine,argument_sequence) 

where

  • id_of_the_routine is an id you obtained from routine_id.
  • argument_sequence is the list of the parameters to pass, enclosed into curly braces
include get.e 
 
constant value_id = routine_id("value") 
result = call_func(value_id, {"Model 36A", 6, GET_LONG_ANSWER}) 
-- result is {GET_SUCCESS, 36, 4, 1} 

This is equivalent to

result = value("Model 36A", 6, GET_LONG_ANSWER) 
Procedure Calling

The same formalism applies, but using call_proc instead. The differences are almost the same as between c_func and c_proc.

include std/pretty.e
Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu